/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package spatial.geometry;

import java.awt.geom.Ellipse2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

/**
 *
 * @author Xiaohui
 */
public class Java2DUtils {
	/**
	 * Given a center and a size, compute the circle.
	 * @param center
	 * @param size
	 * @return
	 */
    public static Ellipse2D.Double compCircleAround(Point2D center, double size) {
        double x = center.getX() - size / 2;
        double y = center.getY() - size / 2;
        return new Ellipse2D.Double(x, y, size, size);
    }
    /**
     * Compute a square with given center and size
     * @param center
     * @param size
     * @return
     */
    
    public static Rectangle2D.Double compSquareAround(Point2D center, double size) {
        double x = (center.getX() - size / 2);
        double y = (center.getY() - size / 2);
        Rectangle2D.Double r = new Rectangle2D.Double(x, y, size,
                size);
        return r;
    }

//    public static Polygon compTriangleAround(Point2D center, double size) {
//        Point2D.Double p1 = new Point2D.Double(center.getX(), center.getY() + size * Math.sqrt(3) / 3);
//        Point2D.Double p2 = new Point2D.Double(center.getX() - size / 2, center.getY() - size * Math.sqrt(3) / 6);
//        Point2D.Double p3 = new Point2D.Double(center.getX() + size / 2, center.getY() - size * Math.sqrt(3) / 6);
//        Polygon polygon= new Polygon();
//        triangle.lineTo(p1.x, p1.y);
//        triangle.lineTo(p2.x, p2.y);
//        triangle.lineTo(p3.x, p3.y);
//        return triangle;
//    }
}
